package com.ms.service.module.analysisgroup;

import com.ms.service.telnet.STelnetCmd;
import com.xpec.c4.service.module.BasicServiceModule;
import com.xpec.c4.service.module.ModuleName;

public class AnalysisGroupModule extends BasicServiceModule{

	private AnalysisGroupProcessor proc;
	
	@Override
	public void init() {
		super.init();
		registerActionClass(AnalysisGroupAction.class);
		registerConsistentGroupName(ModuleName.GROUP_ANALYSIS);
		
		proc = new AnalysisGroupProcessor();
		proc.setModule(this);
		proc.initGameREMap();
		
		//如果是第一個module就檢查看看
		if(this.isFirstModule()){
			getProc().checkAndAddNewCoinExpenditureAlertSetting();
		}
	}
		
	@Override
	public boolean startup() {
		
		//儲存遊戲收支紀錄計時器
		RevenueAndExpenditureLogTimer taskTimer = new RevenueAndExpenditureLogTimer();
		taskTimer.setModule(this);
		taskTimer.setCronExpressions("0 0/30 * 1/1 * ? *");//每30分鐘
		this.addCronTaskTimer(taskTimer);
		
		//清除失效或是過期的cache
		AnalysisGroupCleanerTimer cleanerTimer = new AnalysisGroupCleanerTimer();
		cleanerTimer.setModule(this);
		cleanerTimer.setCronExpressions("0 0/10 * 1/1 * ? *");//每10分鐘
		this.addCronTaskTimer(cleanerTimer);
		
		//儲存物品變化計數計時器
		SaveItemChangeCountTimmer itemCountTimmer = new SaveItemChangeCountTimmer();
		itemCountTimmer.setModule(this);
		itemCountTimmer.setCronExpressions("0 0/1 * 1/1 * ? *");//每分鐘
		this.addCronTaskTimer(itemCountTimmer);
		
		return super.startup();
	}

	@Override
	public void onServerConnectReady(){
		super.onServerConnectReady();
		
		//載入C幣警示設定
		getProc().loadAllCoinExpenditureSetting(true);
	}
	
	@Override
	public void shutdown() {
		super.shutdown();
	}
	
	@Override
	public void procTelnetCommand(STelnetCmd obj) {
		
	}

	public AnalysisGroupProcessor getProc() {
		return proc;
	}
	
}
